<?php

namespace common\models\projectrepo;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\projectrepo\ProjectRepo;

/**
 * ProjectRepoSearch represents the model behind the search form about `common\models\projectrepo\ProjectRepo`.
 */
class ProjectRepoSearch extends ProjectRepo
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'category', 'application_date', 'schedule_starttime', 'schedule_endtime', 'mainpart_age', 'total_budget', 'apply_budget', 'own_budget', 'nation_budget', 'unit_budget', 'other_budget'], 'integer'],
            [['number', 'name', 'firstname', 'secondname', 'repo_unit', 'contacts', 'telephone', 'mobile_phone', 'email', 'fill_instructions', 'leader_name', 'leader_mobile', 'leader_email', 'leader_profession', 'contact_name', 'contact_mobile', 'contact_email', 'contact_address', 'contact_fax', 'contact_telephone', 'coop_name', 'coop_leader', 'coop_telephone', 'repo_unitname', 'repo_supervisor', 'repo_leadername', 'repo_property', 'repo_profile', 'background', 'main_contents', 'existing_basis', 'expected_results', 'schedule_target', 'mainpart_name', 'mainpart_profession', 'mainpart_unit', 'mainpart_mainwork', 'mainpart_note', 'paid_content', 'paid_note', 'calculation_basis', 'repo_option'], 'safe'],
            [['paid_money'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = ProjectRepo::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'category' => $this->category,
            'application_date' => $this->application_date,
            'schedule_starttime' => $this->schedule_starttime,
            'schedule_endtime' => $this->schedule_endtime,
            'mainpart_age' => $this->mainpart_age,
            'total_budget' => $this->total_budget,
            'apply_budget' => $this->apply_budget,
            'own_budget' => $this->own_budget,
            'nation_budget' => $this->nation_budget,
            'unit_budget' => $this->unit_budget,
            'other_budget' => $this->other_budget,
            'paid_money' => $this->paid_money,
        ]);

        $query->andFilterWhere(['like', 'number', $this->number])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'firstname', $this->firstname])
            ->andFilterWhere(['like', 'secondname', $this->secondname])
            ->andFilterWhere(['like', 'repo_unit', $this->repo_unit])
            ->andFilterWhere(['like', 'contacts', $this->contacts])
            ->andFilterWhere(['like', 'telephone', $this->telephone])
            ->andFilterWhere(['like', 'mobile_phone', $this->mobile_phone])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', 'fill_instructions', $this->fill_instructions])
            ->andFilterWhere(['like', 'leader_name', $this->leader_name])
            ->andFilterWhere(['like', 'leader_mobile', $this->leader_mobile])
            ->andFilterWhere(['like', 'leader_email', $this->leader_email])
            ->andFilterWhere(['like', 'leader_profession', $this->leader_profession])
            ->andFilterWhere(['like', 'contact_name', $this->contact_name])
            ->andFilterWhere(['like', 'contact_mobile', $this->contact_mobile])
            ->andFilterWhere(['like', 'contact_email', $this->contact_email])
            ->andFilterWhere(['like', 'contact_address', $this->contact_address])
            ->andFilterWhere(['like', 'contact_fax', $this->contact_fax])
            ->andFilterWhere(['like', 'contact_telephone', $this->contact_telephone])
            ->andFilterWhere(['like', 'coop_name', $this->coop_name])
            ->andFilterWhere(['like', 'coop_leader', $this->coop_leader])
            ->andFilterWhere(['like', 'coop_telephone', $this->coop_telephone])
            ->andFilterWhere(['like', 'repo_unitname', $this->repo_unitname])
            ->andFilterWhere(['like', 'repo_supervisor', $this->repo_supervisor])
            ->andFilterWhere(['like', 'repo_leadername', $this->repo_leadername])
            ->andFilterWhere(['like', 'repo_property', $this->repo_property])
            ->andFilterWhere(['like', 'repo_profile', $this->repo_profile])
            ->andFilterWhere(['like', 'background', $this->background])
            ->andFilterWhere(['like', 'main_contents', $this->main_contents])
            ->andFilterWhere(['like', 'existing_basis', $this->existing_basis])
            ->andFilterWhere(['like', 'expected_results', $this->expected_results])
            ->andFilterWhere(['like', 'schedule_target', $this->schedule_target])
            ->andFilterWhere(['like', 'mainpart_name', $this->mainpart_name])
            ->andFilterWhere(['like', 'mainpart_profession', $this->mainpart_profession])
            ->andFilterWhere(['like', 'mainpart_unit', $this->mainpart_unit])
            ->andFilterWhere(['like', 'mainpart_mainwork', $this->mainpart_mainwork])
            ->andFilterWhere(['like', 'mainpart_note', $this->mainpart_note])
            ->andFilterWhere(['like', 'paid_content', $this->paid_content])
            ->andFilterWhere(['like', 'paid_note', $this->paid_note])
            ->andFilterWhere(['like', 'calculation_basis', $this->calculation_basis])
            ->andFilterWhere(['like', 'repo_option', $this->repo_option]);

        return $dataProvider;
    }
}
